// 通过请求传入参数来获取user数据
const userDao = require('./../dao/userDao.js');

// const mysql = require('./../utils/mysqlUtil.js');

function getData(userId){
    return new Promise((resolve)=>{
        let arr = [
            {
                id: 1024,
                name: 'congcong',
                sex: 'girl',
                age: 24,
                height: 155
            }, {
                id: 1025,
                name: 'xiaofeng',
                sex: 'boy',
                age: 25,
                height: 182
            }
        ]
        resolve(arr.find(item=>item['id']==userId))
    })
}

const getUserById = async (userId) => {
    // let mysqlOptions = {
    //     sql : 'select * from table_user where user_id = ?',
    //     args : [userId]
    // };

    // var users = await mysql.execQuery(mysqlOptions);
    // if(users.length == 0) {
    //     return null;
    // } else {
    //     return users;
    // }
    let users = await getData(userId)
    if(!users) {
        return null;
    } else {
        return users;
    }
};

module.exports = {
    getUserById : getUserById
};